import { useState } from 'react';
const useMessage = (url: string) => {
    let socket = new WebSocket(url)
    const [message, setMessage] = useState('');
    socket.onmessage = (e) => {
        setMessage(e.data)
    }
    const sendMessage = (msg: string) => {
        socket.send(msg)
    }
    socket.onclose = () => {
        socket = new WebSocket(url)
    }
    return { message, sendMessage }
}
export default useMessage;